package com.aiobc.business.dataInfo.controller;

import java.io.IOException;
import java.util.List;

import com.aiobc.business.dataInfo.domain.DataTable;
import com.aiobc.business.dataInfo.service.IDataTableService;
import com.aiobc.common.core.utils.poi.ExcelUtil;
import com.aiobc.common.core.web.controller.BaseController;
import com.aiobc.common.core.web.domain.AjaxResult;
import com.aiobc.common.core.web.page.TableDataInfo;
import com.aiobc.common.log.annotation.Log;
import com.aiobc.common.log.enums.BusinessType;
import com.aiobc.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;


/**
 * 数据模型Controller
 * 
 * @author xc
 * @date 2021-10-22
 */
@Controller
@RequestMapping("/dataInfo/dataTable")
public class DataTableController extends BaseController
{


    @Autowired
    private IDataTableService dataTableService;


    /**
     * 查询数据模型列表
     */
    @PreAuthorize(hasPermi ="dataInfo:dataTable:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataTable dataTable)
    {
        startPage();
        List<DataTable> list = dataTableService.selectDataTableList(dataTable);
        return getDataTable(list);
    }

    /**
     * 导出数据模型列表
     */
    @PreAuthorize(hasPermi ="dataInfo:dataTable:export")
    @Log(title = "数据模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, DataTable dataTable) throws IOException {
        List<DataTable> list = dataTableService.selectDataTableList(dataTable);
        ExcelUtil<DataTable> util = new ExcelUtil<DataTable>(DataTable.class);
         util.exportExcel(response,list ,"数据模型数据");
    }


    /**
     * 新增保存数据模型
     */
    @PreAuthorize(hasPermi ="dataInfo:dataTable:add")
    @Log(title = "数据模型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataTable dataTable)
    {
        return toAjax(dataTableService.insertDataTable(dataTable));
    }

    /**
     * 修改数据模型
     */
    @GetMapping("/edit/{dataId}")
    public String edit(@PathVariable("dataId") String dataId, ModelMap mmap)
    {
        DataTable dataTable = dataTableService.selectDataTableByDataId(dataId);
        mmap.put("dataTable", dataTable);
        return  "/edit";
    }

    /**
     * 修改保存数据模型
     */
//    @RequiresPermissions("dataInfo:dataTable:edit")
    @Log(title = "数据模型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataTable dataTable)
    {
        return toAjax(dataTableService.updateDataTable(dataTable));
    }

    /**
     * 删除数据模型
     */
//    @RequiresPermissions("dataInfo:dataTable:remove")
    @Log(title = "数据模型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dataTableService.deleteDataTableByDataIds(ids));
    }
}
